package com.ad.models;

import com.ad.system.Common;

public class City {

	private String whole;

	private String city;

	private String province;

	private String ip;

	public City(String rawCityInfo) {
		String ip = Common.splitMatchFirst(">", "<", rawCityInfo);
		if (!Common.isEmpty(ip)) {
			this.setIp(ip);
		}
		String rawCity = Common.splitMatchLast(">", "<", rawCityInfo);
		if (Common.isEmpty(rawCity)) {
			return;
		}

		if (rawCity.contains("市")) {
			rawCity = rawCity.split("市")[0];
		}
		this.setWhole(rawCity);
		this.setCity(rawCity);
		this.setProvince(rawCity);

		String[] cityNPro = null;
		if (rawCity.contains("省")) {
			cityNPro = rawCity.split("省");
			this.setProvince(cityNPro[0]);
			if (cityNPro.length == 2)
				this.setCity(cityNPro[1]);
			else
				this.setCity("");
		} else if (rawCity.contains("自治区")) {
			cityNPro = rawCity.split("自治区");
			this.setProvince(cityNPro[0]);
			if (cityNPro.length == 2)
				this.setCity(cityNPro[1]);
			else
				this.setCity("");
		}

	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getWhole() {
		if (Common.isEmpty(whole)) {
			whole = this.province + "省" + this.city + "市";
		}
		return whole;
	}

	public void setWhole(String whole) {
		this.whole = whole;
	}

}